/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project.jpdftools.ui.logic;

import com.itextpdf.text.Document;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import project.jpdfexport.constants.JPDFConst.ALIGNMENT;
import project.jpdfexport.constants.JPDFConst.STYLE;
import project.jpdfexport.jpdf.PDFTable;

/**
 *
 * @author Mido
 */
public class JPDFTable extends JPDF {

    private int tableAlignment;
    private Color tableHeaderColor;
    private boolean displayColumnNames;
    private String fontPathName;
    private int fontSize;
    private Color fontColor;
    private int fontStyle;
    private int spaceAfter;
    // UI components
    private JTable table;

    public JPDFTable(int rows, int columns) {
        // default values
        this.tableAlignment = ALIGNMENT.left;
        this.tableHeaderColor = Color.white;
        this.displayColumnNames = true;
        this.fontSize = 12;
        this.fontColor = Color.black;
        this.fontStyle = STYLE.normal;
        this.spaceAfter = 5;
        scrollPane = new JScrollPane(table);
        // intialize the table with the rows and columns
        table = new JTable(rows, columns);
    }

    @Override
    public void export(Document document) {
        if (fontPathName != null) {
            PDFTable.addTable(document, table, project.jpdftools.toolkit.Toolkit.getFontPath(fontPathName), spaceAfter, tableHeaderColor, displayColumnNames,
                    fontSize, fontColor, fontStyle, tableAlignment);
        } else {
            PDFTable.addTable(document, table, null, spaceAfter, tableHeaderColor, displayColumnNames, fontSize, fontColor, fontStyle, tableAlignment);
        }
    }

    @Override
    public void createUI() {
        // get the screen resolution
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

        scrollPane.setPreferredSize(new Dimension(screen.width - 180, 100));
        scrollPane.setViewportView(table);
        panel.setPreferredSize(new Dimension(screen.width - 180, 130));

        // add component to the panel
        panel.add(scrollPane);
    }

    public boolean isDisplayColumnNames() {
        return displayColumnNames;
    }

    public void setDisplayColumnNames(boolean display_column_names) {
        this.displayColumnNames = display_column_names;
    }

    public Color getFontColor() {
        return fontColor;
    }

    public void setFontColor(Color font_color) {
        this.fontColor = font_color;
    }

    public String getFontPathName() {
        return fontPathName;
    }

    public void setFontPathName(String font_path_name) {
        this.fontPathName = font_path_name;
    }

    public int getFontSize() {
        return fontSize;
    }

    public void setFontSize(int font_size) {
        this.fontSize = font_size;
    }

    public int getFontStyle() {
        return fontStyle;
    }

    public void setFontStyle(int font_style) {
        this.fontStyle = font_style;
    }

    public int getSpaceAfter() {
        return spaceAfter;
    }

    public void setSpaceAfter(int space_after) {
        this.spaceAfter = space_after;
    }

    public JTable getTable() {
        return table;
    }

    public void setTable(JTable table) {
        this.table = table;
    }

    public int getTableAlignment() {
        return tableAlignment;
    }

    public void setTableAlignment(int table_alignment) {
        this.tableAlignment = table_alignment;
    }

    public Color getTableHeaderColor() {
        return tableHeaderColor;
    }

    public void setTableHeaderColor(Color table_header_color) {
        this.tableHeaderColor = table_header_color;
    }
}
